/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package coda.gui;

import java.awt.Font;
import java.awt.Window;
import javax.swing.UIManager;
import javax.swing.plaf.FontUIResource;

/**
 *
 * @author pan
 */
public class Look {

    private static Look instance = null;
    private static FontUIResource plain;
    private static FontUIResource bold;

    protected Look() {
        plain = new FontUIResource("Verdana", Font.PLAIN, 11);
        bold = new FontUIResource("Verdana", Font.BOLD, 11);

        for (String s : new String[] {"Label", "TextField", "ComboBox", "MenuItem", "CheckBox", "List", "TextArea"}) {
            UIManager.put(s + ".font", plain);
        }
        for (String s : new String[] {"Button", "Menu"}) {
            UIManager.put(s + ".font", bold);
        }
    }

    public static Look getInstance() {
        if (instance == null) {
            instance = new Look();
        }
        return instance;
    }

    public static Look newInstance(boolean aatext) {
        if (instance == null) {
            if (aatext) {
                System.setProperty("awt.useSystemAAFontSettings", "on");
                System.setProperty("swing.aatext", "true");
            }
        }
        return getInstance();
    }

    public void setNativeLaf() {
        String laf;
        if (System.getProperty("os.name").toLowerCase().contains("linux")) {
            laf = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
        } else {
            laf = UIManager.getSystemLookAndFeelClassName();
        }
        try {
            UIManager.setLookAndFeel(laf);
        } catch (Exception e) {
            System.err.println("Can't set native l&f");
        }
    }

    public void setMetalLaf() {
        try {
            UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
        } catch (Exception e) {
            System.err.println("Could not set metal l&f");
        }
    }

    public void updateUI() {
        for (Window w : MainForm.getWindows()) {
            javax.swing.SwingUtilities.updateComponentTreeUI(w);
        }
    }

}
